package org.example.day10;

import java.util.Date;

/**
 * 3.4.1: 类InheritableThreadLocal的使用
 * 作用:可以在子线程中取得父线程继承下来的值
 */
public class MyThread4 extends InheritableThreadLocal{
    @Override
    protected Object initialValue() {
        return new Date().getTime();
    }

    public static void main(String[] args) {
        try {
            for (int i = 0; i < 10; i++) {
                System.out.println("在main线程中取值:" + Tools.t1.get());
                Thread.sleep(100);
            }
            Thread.sleep(6000);
            Thread4A ta = new Thread4A();
            ta.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Tools {
    public static MyThread4 t1 = new MyThread4();
}

class Thread4A extends Thread{
    @Override
    public void run() {
        try {
            for (int i = 0; i < 10; i++) {
                System.out.println("在ThreadA线程中取值" + Tools.t1.get());
                Thread.sleep(100);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}